package com.sunsy.authserver.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sunsy.authserver.beans.po.UniformUser;
import com.sunsy.authserver.beans.po.UserAppRelation;
import com.sunsy.authserver.beans.vo.AdminUserVO;
import com.sunsy.authserver.beans.vo.UniformUserVO;
import com.sunsy.authserver.dao.UniformUserDao;
import com.sunsy.authserver.dao.UserAppRelationDao;
import com.sunsy.authserver.service.UserAppRelationService;
import com.sunsy.authserver.wrapper.UniformUserWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * (UserAppRelation)表服务实现类
 *
 * @author makejava
 * @since 2021-07-20 14:40:43
 */
@Service("userAppRelationService")
public class UserAppRelationServiceImpl extends ServiceImpl<UserAppRelationDao, UserAppRelation> implements UserAppRelationService {

    private UniformUserDao userDao;

    @Autowired
    public void setUserDao(UniformUserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public int delByAppId(Long appId) {
        return baseMapper.delByAppId(appId);
    }

    @Override
    public List<AdminUserVO> getUserList(Long aId) {
        List<AdminUserVO> list = userDao.getAllUser();
        Map<Long, AdminUserVO> map = list.stream().collect(Collectors.toMap(AdminUserVO::getId, user -> user));
        List<Long> uIds = baseMapper.getUserList(aId);
        uIds.stream().forEach(it -> {
            map.get(it).setChecked(true);
        });
        return list;
    }
}